﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using System.Reflection;
using log4net;


namespace AnyOffice.general.system.bbs
{
    public partial class edit : ModulePage
    {
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int boardId = (Request.QueryString["board_id"] != null) ? Convert.ToInt32(Request.QueryString["board_id"].ToString()) : 0;
                this.ViewState["BoardId"] = boardId;
                try
                {
                    DataTable table = new BbsBoardDao().SelectByBoardId(base.Conn, boardId);
                    if (table.Rows.Count > 0)
                    {
                        this.txtBoardNo.Value = table.Rows[0]["BoardNo"].ToString();
                        this.txtBoardName.Value = table.Rows[0]["BoardName"].ToString();
                        this.txtWelcomeText.Value = (table.Rows[0]["WelcomeText"] != DBNull.Value) ? table.Rows[0]["WelcomeText"].ToString() : "";
                        this.DeptId.Value = (table.Rows[0]["DeptId"] != DBNull.Value) ? table.Rows[0]["DeptId"].ToString() : "";
                        this.DeptName.Value = (table.Rows[0]["DeptName"] != DBNull.Value) ? table.Rows[0]["DeptName"].ToString() : "";
                        this.Owner.Value = (table.Rows[0]["Owner"] != DBNull.Value) ? table.Rows[0]["Owner"].ToString() : "";
                        this.OwnerName.Value = (table.Rows[0]["OwnerName"] != DBNull.Value) ? table.Rows[0]["OwnerName"].ToString() : "";
                        if (this.sltIsAnonymous.Items.FindByValue(table.Rows[0]["IsAnonymous"].ToString()) != null)
                        {
                            this.sltIsAnonymous.Items.FindByValue(table.Rows[0]["IsAnonymous"].ToString()).Selected = true;
                        }
                    }
                    else
                    {
                        this.pnlMain.Visible = false;
                        this.litMessage.Text = base.ShowPrompt("无记录！");
                    }
                }
                catch (Exception exception)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception);
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                try
                {
                    BbsBoardDao dao2 = new BbsBoardDao();
                    BbsBoardData data = new BbsBoardData();
                    data.BoardId = Convert.ToInt32(this.ViewState["BoardId"].ToString());
                    data.BoardNo = Convert.ToInt32(this.txtBoardNo.Value);
                    data.BoardName = this.txtBoardName.Value;
                    data.WelcomeText = this.txtWelcomeText.Value;
                    data.DeptId = this.DeptId.Value;
                    data.Owner = this.Owner.Value;
                    data.IsAnonymous = Convert.ToBoolean(this.sltIsAnonymous.Value);
                    dao2.Update(base.Conn, data);
                }
                catch (Exception exception2)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("", exception2);
                    }
                }
                base.CloseConn();
                Response.Redirect("index.aspx");
            }
        }
 

    }
}
